<script lang="ts">
	import { getUserImInfo,totalMesCount} from '@/utils/api/userInfo.ts'
	// #ifdef APP-PLUS
	import interception from '@/stores/interception.js';
	import {initPush} from '@/utils/push.ts'
	import {connectWebsocket,disconnectWebsocket} from '@/utils/websocket.ts';
	import {up_check} from '@/utils/index.ts'
	initPush()
	up_check()
	setInterval(()=>{
		up_check()
	},60000)
	// #endif
	import {connectIm,notReadCount} from '@/utils/tencent.ts'
	import {requestAndroidPermission} from '@/js_sdk/wa-permission/permission.js'
	export default {
		globalData: {
			// baseUrl: 'http://api.yiquduozi.top',  //线上
			baseUrl: 'http://api-test.yiquduozi.top',  //测试环境
			getUserInfo :function(){
				 // #ifdef APP-PLUS
				 // #endif
				 connectIm()
			}
			// baseUrl: 'http://192.168.0.26:9005'
		},
		onLaunch: function () {
			interception()
			console.log('App Launch')
		
			
			uni.onTabBarMidButtonTap(() => {
				const token = uni.getStorageSync('token')
				if (!token) {
					uni.navigateTo({
						url: `/pages/login/login`
					})
					return
				}
				uni.navigateTo({
					url: `/pages/releaseRequirements/index`,
				})
			})

			uni.addInterceptor('switchTab', {
				invoke(e) {
					if (e.url == '/pages/TUIKit/components/TUIConversation/index') {
						connectIm()						
					}
				},
				success: (e) => {
					console.log('OK', e)
					if(notReadCount.value>0){
						uni.showTabBarRedDot({
							index: 2
						})
					}else{
						uni.hideTabBarRedDot({
							index: 2
						})
					}
				}
			})
			//增加统一登录验证 没有token不跳转页面
			uni.addInterceptor('navigateTo', {
				invoke(e) {
					const arr = ['/pages/index/index', '/pages/login/login', '/pages/my/serviceAgreement',
						'/pages/reset/reset', '/pages/reset/resetPayPw','/pages/fillPhone/index']
					let url = e.url
					if (url.indexOf('?') != -1) {
						url = url.slice(0, url.indexOf('?') + 1)
					}
					if (arr.indexOf(url)) {
						return true
					} else {
						const token = uni.getStorageSync('token')
						if (!token) {
							uni.navigateTo({
								url: `/pages/login/login`
							})
							return false
						} else {
							return true
						}
					}
				},
				success: (e) => {
					console.log('OK', e)
					if(notReadCount.value>0){
						uni.showTabBarRedDot({
							index: 2
						})
					}else{
						uni.hideTabBarRedDot({
							index: 2
						})
					}
				}
			})

		},
		onShow: function () {
			console.log('App Show')
			const user = uni.getStorageSync('userInfo')
			connectWebsocket(user?.userId)
			if(user){
				connectIm()
			}
			
		},
		onHide: function () {
			console.log('App Hide')
			totalMesCount().then(res=>{
				plus.runtime.setBadgeNumber(res.data);
			})
			console.log('App Hide..........')
		}
	}
</script>

<style lang="scss">
	@import url(static/css/common.css);

	@font-face {
		font-family: 'MyFont';
		src: url('~@/static/fonts/AlibabaPuHuiTi-2-55-Regular.ttf') format('truetype');
	}
	
	@font-face {
		font-family: 'MyFont1';
		src: url('~@/static/fonts/characterSoulTonsil.ttf') format('truetype');
	}

	* {
		box-sizing: border-box;
	}

	text,
	view {
		font-family: 'MyFont';
		font-size: 28rpx;
		color: #262626;
	}

	// image {
	// 	height: auto;
	// }
	image{
		height: auto;
	}
	.priceText {

		&:before {
			content: '￥';
			display: inline-block;
			font-size: 24rpx;
			color: #FF5233;
		}

		text:nth-of-type(1) {
			font-size: 36rpx;
			color: #FF5233;
		}

		text:nth-of-type(2) {
			font-size: 24rpx;
			color: #FF5233;
		}

		.priceText_1 {
			font-size: 36rpx;
			color: #FF5233;
		}

		.priceText_2 {
			font-size: 24rpx;
			color: #FF5233;
		}
	}

	.ellipsis_2 {
		word-break: break-all;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		/* 设置超出的行数 */
		overflow: hidden;
	}

	.ellipsis_1 {
		word-break: break-all;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		/* 设置超出的行数 */
		overflow: hidden;
	}
	// #app{
	// 	background: #F4F6FA;
	// }

	/*每个页面公共css */
</style>